package com.itboye.lottery.activity

import android.content.Intent
import android.os.Handler
import android.view.View
import com.itboye.lottery.MainActivity
import com.itboye.lottery.R
import com.itboye.lottery.base.BaseActivity
import com.itboye.lottery.logincontroller.LoginController
import com.itboye.lottery.logincontroller.LoginedState
import com.itboye.lottery.logincontroller.UnLoginState
import com.itboye.lottery.utils.Const
import com.itboye.lottery.utils.Flavor
import com.itboye.lottery.utils.SPUtils.getSp
import kotlinx.android.synthetic.main.activity_splash.*

class SplashActivity : BaseActivity() {
    override fun getLayoutId(): Int {
        return R.layout.activity_splash
    }

    override fun initData() {
        iv_splash.setImageResource(Flavor().splash)
        Handler().postDelayed({
            //初始化登录状态
            initLoginStatus()
        }, 1000)
    }

    private fun initLoginStatus() {
        if (getSp(Const.UID) == null || "".equals(getSp(Const.UID))) {
            LoginController.setLoginState(UnLoginState())
            val intent = Intent(this@SplashActivity, LoginActivity::class.java)
//            val intent = Intent(this@SplashActivity, MainActivity::class.java)
            startActivity(intent)
            finish()
        } else {
            LoginController.setLoginState(LoginedState())
            val intent = Intent(this@SplashActivity, MainActivity::class.java)
            startActivity(intent)
            finish()
        }
    }

    override fun onClick(p0: View?) {
    }
}
